import java.util.Scanner;

/**
 * Created with IDEA
 * author:ju bai
 * Date:2021/4/21
 * Time:21:16
 **/
public class Main1 {
    /**
     * 每日一题-Fibonacci 数列步数问题
     * @param args
     */
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            int n = sc.nextInt();
            int cur = 0;
            int first = 0;
            int second = 1;
            while(second <= n){
                cur = first + second;
                first = second;
                second = cur;
            }
            //System.out.println((second-n)>(n-first)?n-first:second-n);
            System.out.println(Math.min((second - n), (n - first)));

        }
    }
}
